import {encryptFile} from "@/store/DES3";

var encrypt = new JSEncrypt();
var key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+K3y4fL71dFhFYC9c9bea9wPH" + "\r" +
      "youU86VI0nI1GtDiMbSd3/mFcf/Z14hixordW8W8Q0BftncjcbIOHOeHDK074hpV" + "\r" +
      "bMdJTgadisuksX1fISp5CXa5ETsDcHa6usb1wGd2EFSo8ws5Jfi5oGZVgRzF3YLI" + "\r" +
      "KgxYn+NZu7cvHOD0GwIDAQAB" + "\r";
encrypt.setPublicKey(key);

//正文原文附件
export function openFileUrl(url) {
    if(process.env.VUE_APP_OPENFILE=="http://10.92.82.161:8088/"){
        return url;
    }else {
        url = process.env.VUE_APP_OPENFILE+"webOffice/?furl=" + url;
        var a = encrypt.encrypt("maip2015");
        var des3url=encryptFile("2015#@mocha$#soft0803#$@",url);
        url =process.env.VUE_APP_OPENFILE+ "maip/action/anonymous/fileAuthentication/authenticate?url=" + replaceD(encodeURIComponent(des3url)) + "&token=" + replaceD(encodeURIComponent(a));
        return url;
    }
};
//替换url.-+
function replaceD(str) {
    var len = str.split(".").length + 1;
    for (var i = 0; i < len; i++) {
        str = str.replace(".", "%2E");
    }
    var len = str.split("-").length + 1;
    for (var i = 0; i < len; i++) {
        str = str.replace("-", "%2D");
    }
    var len = str.split("+").length + 1;
    for (var i = 0; i < len; i++) {
        str = str.replace("+", "%2B");
    }
    var len = str.split("/").length + 1;
    for (var i = 0; i < len; i++) {
        str = str.replace("/", "%2F");
    }
    var len = str.split("=").length + 1;
    for (var i = 0; i < len; i++) {
        str = str.replace("=", "%3D");
    }
    return str;
};